package com.zhika.zishi.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.zhika.zishi.R;
import com.zhika.zishi.activity.BaseActivity;
import com.zhika.zishi.adapter.MySelfLikeStrategyAdapter;
import com.zhika.zishi.adapter.MySelfLikeStrategyBean;
import com.zhika.zishi.beans.MySelfSPBean;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.interfaces.TitleInterface;
import com.zhika.zishi.util.LogUtil;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/23.
 */
public class MySelfLikeStrategyActivity extends BaseActivity {

    private final String TAG = "MySelfLikeStrategyActivity";

    private TitleView titleView;

    private ListView listView;

    private ArrayList<MySelfLikeStrategyBean> likeStrategyBeans = new ArrayList<>();

    private MySelfLikeStrategyAdapter adapter;

    private ImageView lastImageView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myself_like_strategy);

        addTestData();
        initView();

    }

    private void initView(){
        titleView = (TitleView) findViewById(R.id.myself_like_strategy_title_view);
        titleView.setLeftButtonText("返回");
        titleView.setMiddleRowText("我关注的攻略");
        titleView.hideRightButton();
        titleView.setTitleViewInterface(new TitleInterface() {
            @Override
            public void leftTitleListener() {
                finish();
            }

            @Override
            public void middleTitleListener() {

            }

            @Override
            public void rightTitleListener() {
                finish();
            }
        });

        listView = (ListView) findViewById(R.id.myself_like_strategy_list_view);
        adapter = new MySelfLikeStrategyAdapter(MySelfLikeStrategyActivity.this,likeStrategyBeans);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                LogUtil.e(TAG,"listView被点击了");
                titleView.setRightButtonText("确定");
                titleView.showRightButton();
                if (lastImageView!=null){
                    lastImageView.setVisibility(View.GONE);
                }
                lastImageView = (ImageView) view.findViewById(R.id.item_of_myself_like_strategy_image_view);
                lastImageView.setVisibility(View.VISIBLE);
            }
        });

    }

    private void addTestData(){
        for (int i = 0;i<8;i++){
            MySelfLikeStrategyBean bean= new MySelfLikeStrategyBean();
            bean.setNicknameStr("攻略者昵称");
            bean.setStrategyTitleStr("攻略题目攻略题目攻略题目");

            likeStrategyBeans.add(bean);
        }
    }
}
